<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "major_course".
 *
 * @property int $ZYID 专业ID
 * @property int $KCID 课程ID
 * @property int $PKXQXH 排课学期序号
 *
 * @property Major $zY
 * @property Course $kC
 */
class MajorCourse extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'major_course';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['ZYID', 'KCID', 'PKXQXH'], 'required'],
            [['ZYID', 'KCID', 'PKXQXH'], 'integer'],
            [['ZYID', 'KCID'], 'unique', 'targetAttribute' => ['ZYID', 'KCID']],
            [['ZYID'], 'exist', 'skipOnError' => true, 'targetClass' => Major::className(), 'targetAttribute' => ['ZYID' => 'ID']],
            [['KCID'], 'exist', 'skipOnError' => true, 'targetClass' => Course::className(), 'targetAttribute' => ['KCID' => 'ID']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'ZYID' => '专业ID',
            'KCID' => '课程ID',
            'PKXQXH' => '排课学期序号',
        ];
    }

    /**
     * Gets query for [[ZY]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getZY()
    {
        return $this->hasOne(Major::className(), ['ID' => 'ZYID'])->inverseOf('majorCourses');
    }

    /**
     * Gets query for [[KC]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getKC()
    {
        return $this->hasOne(Course::className(), ['ID' => 'KCID'])->inverseOf('majorCourses');
    }
}
